package com.xxh.blog.mq;

import com.xxh.blog.config.RabbitMqConfig;
import com.xxh.blog.service.SearchService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消费者监听指定队列
 */
@Component
@RabbitListener(queues = RabbitMqConfig.ES_QUEUE)
public class MessageHandler {
    @Autowired
    SearchService searchService;


    @RabbitHandler
    public void hander(PostMqMessage message){
        System.out.println(message.getType());
        switch (message.getType()){
            case PostMqMessage.CREATE_OR_UPDATE:
                System.out.println("收到了更新的消息");
                searchService.creatOrUpdateIndex(message);
                break;
            case PostMqMessage.REMOVE:
                System.out.println("收到了删除的消息");
                searchService.removeIndex(message);
                break;
            default:
                break;
        }
    }
}
